package demo.huangli.mydemosnew.ui_set_1.web;

import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import demo.huangli.mydemosnew.R;

/**
 * Created by huangli on 17/12/28.
 * 通过浏览器启动
 */

public class H5toAppActivity extends Activity{

    private WebView webView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_h5_to_app);
        webView = findViewById(R.id.web_view);
        webView.loadUrl("file:///android_asset/javascript_skip.html");
        attachClient();
    }

    private void attachClient() {
        //设置不用系统浏览器打开,直接显示在当前Webview
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }

            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);
                System.out.println("开始加载了");
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                System.out.println("结束加载了");
            }
        });
    }
}
